package app.util.image.action
{
	import app.util.*;
	
	import flash.display.*;
	import flash.filters.*;
	import flash.geom.*;
	
	public class SprayAction extends AbstractAction
	{
		private var value:Number = 0;
		
		public function setValue(s:Number):SprayAction
		{
			this.value = s;
			
			return this;
		}
		
		public override function getDescription():String
		{
			return "Spray (" + this.value.toFixed(1) + ")";
		}
		
		public override function getActionedBitmapData():BitmapData
		{
			var old:BitmapData = Mediator.getCurrentBitmapData();
			var bmp:BitmapData = new BitmapData(old.width, old.height); 
			var ret:BitmapData = old.clone();
			var v:Number = this.value * 8;
			bmp.noise(1);
			var filter:DisplacementMapFilter = new DisplacementMapFilter(bmp, 
            								new Point(0, 0), 1, 1, v, v, DisplacementMapFilterMode.COLOR, 0, 0);
            ret.applyFilter(ret, ret.rect, new Point(0, 0), filter);
			return ret;
		}	
	}
}